﻿using HelloWPF.Command.Command;
using HelloWPF.Command.Models;
using HelloWPF.Command.Views;
using HelloWPF.FirstMVVM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HelloWPF.Command.ViewModel
{
    public class PopupWindowViewModel: CommandBase
    {
        public CommandBase BtnShowDialogCommand { get; set; }


        public PopupWindowViewModel()
        {
            BtnShowDialogCommand = new CommandBase()
            {
                DoExecute = new Action<object>((obj) => {
                    //直接在ViewModel层调用View层，产生了耦合
                    //PopupWindow popupWindow = new PopupWindow();
                    //popupWindow.ShowDialog();

                   
                    PopupModel<string> popupModel = new PopupModel<string>();
                    popupModel.Value = obj.ToString();

                    //经过这样的封装，解耦了在ViewModel层直接使用View
                    WindowManager.ShowDialog<PopupModel<string>>("PopupWindow", popupModel);
                }),
                DoCanExecute = new Func<object, bool>((obj) => {
                    return true;
                })
            };
        }
    }
}
